import 'package:t3_data_service/biz_data_source/map/address/city_pick/model/city_pick_models.dart';
import 'package:t3_data_service/biz_data_source/map/address/poi_search/poi_search.dart';
import 'package:t3_data_service/data_provider/map_sctx/t3_map_sctx_provider.dart';
import 'package:t3_foundation/t3_foundation.dart';

class AddressSelectConfig {
  /// 基础位置信息
  /// 切换城市、搜索位置的起点、图选地图中心点等等
  /// - note!!!: 单点城市城市选择好理解；对于目的地这种多点选择，则指光标所在输入框位置信息
  /// - note: 如果为空，则使用首页大头针位置
  T3POILocation? location;
  /// 订单起点位置，搜索结果中的距离参考点
  LatLng? originCoor;
  /// 是否允许移出围栏
  bool allowMoveOutFence = true;
  /// 起终点、途经点
  T3POIType pointType = T3POIType.start;
  /// 订单中是否允许修改终点
  bool isUserActionDisabledForEnd = false;
  /// 订单中是否允许修改途经点
  bool isUserActionDisabledForVia = false;
  /// 是否需要 隐藏 添加途经点 按钮
  bool needHideAddMidwayButton = false;
  /// 展示样式: 普通、老年人、自动驾驶
  T3POIStyle style = T3POIStyle.normal;
  /// 城市范围
  CityScope cityScope = CityScope.opened;
  /// 是否展示tableview的图选footer：目前仅途经点和目的地搜索展示
  bool showMapSelectedFooter = false;
  /// 多点与图选配置
  bool showConfusionButton = true;
  /// 搜索框是否展示返回按钮：图选页面需要展示
  bool showBackButton = false;
  /// 企业用车使用
  String? sceneRuleId;
  /// 埋点使用
  String? refererPageTitle;
  /// 地图类型
  T3MapType mapType = T3MapSctxProvider.instance.currentMapType;
  /// 首页起点为false，地点错误上报页面为false
  /// 选点后是否校验围栏、多下车点
  bool shouldCheckTableSelectedPoi = true;

  AddressSelectConfig({
    required this.location,
    this.originCoor,
    this.sceneRuleId,
    this.refererPageTitle,
    this.allowMoveOutFence = true,
    this.pointType = T3POIType.start,
    this.isUserActionDisabledForEnd = false,
    this.isUserActionDisabledForVia = false,
    this.needHideAddMidwayButton = false,
    this.style = T3POIStyle.normal,
    this.cityScope = CityScope.opened,
    this.showMapSelectedFooter = false,
    this.showConfusionButton = true,
    this.showBackButton = false,
    this.shouldCheckTableSelectedPoi = true,
  });

  Map<String, dynamic> toJson() {
    return {
      'location': location?.toJson(),
      'originCoor': originCoor?.toJson(),
      'allowMoveOutFence': allowMoveOutFence,
      'pointType': pointType.type,
      'isUserActionDisabledForEnd': isUserActionDisabledForEnd,
      'isUserActionDisabledForVia': isUserActionDisabledForVia,
      'needHideAddMidwayButton': needHideAddMidwayButton,
      'style': style.style,
      'cityScope': cityScope.value,
      'showMapSelectedFooter': showMapSelectedFooter,
      'showConfusionButton': showConfusionButton,
      'showBackButton':showBackButton,
      'sceneRuleId': sceneRuleId,
      'refererPageTitle': refererPageTitle,
      'mapType': mapType.value,
      'shouldCheckTableSelectedPoi': shouldCheckTableSelectedPoi,
    };
  }

  static AddressSelectConfig fromJson(Map<dynamic, dynamic> json) {
    var config = AddressSelectConfig(
      location: null,
      originCoor: LatLng.fromJson(json['originCoor']),
      allowMoveOutFence: BoolUtils.dynamicToBool(json['allowMoveOutFence'], true),
      pointType: T3POIType.fromJson(IntUtils.dynamicToNullInt(json['pointType'])),
      isUserActionDisabledForEnd: BoolUtils.dynamicToBool(json['isUserActionDisabledForEnd']),
      isUserActionDisabledForVia: BoolUtils.dynamicToBool(json['isUserActionDisabledForVia']),
      needHideAddMidwayButton: BoolUtils.dynamicToBool(json['needHideAddMidwayButton']),
      style: T3POIStyle.fromJson(IntUtils.dynamicToNullInt(json['style'])),
      cityScope: CityScopeExtension.initWithRawValue(IntUtils.dynamicToNullInt(json['cityScope'])) ?? CityScope.opened,
      showMapSelectedFooter: BoolUtils.dynamicToBool(json['showMapSelectedFooter']),
      showConfusionButton: BoolUtils.dynamicToBool(json['showConfusionButton'],true),
      showBackButton: BoolUtils.dynamicToBool(json['showBackButton']),
      sceneRuleId: StringUtils.dynamicToString(json['sceneRuleId']),
      refererPageTitle: StringUtils.dynamicToString(json['refererPageTitle']),
      shouldCheckTableSelectedPoi: BoolUtils.dynamicToBool(json['shouldCheckTableSelectedPoi'], true),
    );
    config.mapType = T3MapType.fromJson(IntUtils.dynamicToNullInt(json['mapType']));
    return config;
  }

  bool get isStartPoint {
    return pointType == T3POIType.start;
  }
}
